package com.cat.service.Impl;

import com.cat.dao.Impl.StudentDaoImpl;
import com.cat.dao.inter.StudentDao;
import com.cat.pojo.Student;
import com.cat.service.inter.UploadService;

import java.util.List;
/**
 * @name UploadService
 * @description 用于提供用户上传和更新头像的服务
 * @notice none
 * @author HYC kobe524348@gmail.com
 * @date 2019/4/2
 */
public class UploadServiceImpl implements UploadService {

    StudentDao studentDAO = new StudentDaoImpl();

    Student stu = null;

    /**
     * @name upload
     * @author HYC kobe524348@gmail.com
     * @param  stuId 传入要更新头像的学生id
     * @param  path 传入头像图片的相对路径
     * @description 根据头像和图片路径更新学生的头像
     * @notice none
     * @date 2019/4/2
     */

    @Override
    public void upload(String stuId, String path) {
        StudentServiceImpl serv = new StudentServiceImpl();
        //取得学号对应的学生，设置头像路径，再更新这个学生的信息
        List<Student> list = studentDAO.findStudent("studentId", stuId);
        if (list.size() > 0) {
            stu = list.get(0);
            if (stu != null) {
                stu.setPortrait(path);
                studentDAO.updateStudent(stu);
            }
        }
    }
}
